#include "buffer_manager.h"

namespace jlib {


BufferObject *BufferManager::get (const std::string &name) noexcept {
  auto iter = this->_cache.find(name);
  if (iter == this->_cache.end())
    return nullptr;
  return iter->second;
}


BufferObject *BufferManager::get (const std::string &name, GLenum type, GLenum usage, GLsizei size) noexcept {
  auto &ptr = this->_cache[name];
  if (!ptr)
    ptr = Object::create<BufferObject>(type, usage, size);
  return ptr;
}


void BufferManager::add (const std::string &name, BufferObject *buffer) noexcept {
  this->_cache[name] = buffer;
}


void BufferManager::clear () noexcept {
  this->_cache.clear();
}


} // namespace jlib
